<template>
	<view>
		<view class="topbox">
			<view class="searchbox">
				<view class="adress">
					<image class="adimg" src="https://daiyue.gzzhenyi.net/static/index/address.png" mode="widthFix">
					</image>
					<text>广州</text>
				</view>
				<van-search class="search" :value="searchValue" @search="onSearch" shape="round"
					placeholder="请输入搜索关键词" />
			</view>
			<view class="tabbox">
				<van-dropdown-menu>
					<van-dropdown-item :value="zhdropdownValue" :options="zhdropdownOption" />
				</van-dropdown-menu>
				<view class="liaol">距离优先</view>
				<van-dropdown-menu>
					<van-dropdown-item :value="mddropdownValue" :options="mddropdownOption"
						@change="onMddropdownChange" />
				</van-dropdown-menu>
			</view>
		</view>
		<view class="content">
			<view class="item" v-for="(item, index) in list">
				<view class="chanpin">
					<image :src="baseUrl + item.store_avatar"></image>
					<view class="tright">
						<view class="title">
							<text>{{ item.store_name }}</text>
							<!-- <text class="jltxt">{{ item.tag }}</text> -->
							<text class="juli">{{ item.distance.formatted_distance }}</text>
						</view>
						<view class="distance">
							<view>
								<text>评分 </text>
								<text class="orange"> {{ item.grade }}</text>
							</view>
							<view>
								<text>销量 </text>
								<text class="orange"> {{ item.sales }}</text>
							</view>
						</view>
						<view class="address">{{ item.address }}</view>
					</view>
				</view>
				<view class="ziti" @click="radio = index">
					<text>上门自提</text>
					<van-icon name="checked" size="30rpx" color="#FF6200" v-if="index == radio" />
					<van-icon name="circle" size="30rpx" color="#999" v-else />
				</view>
			</view>
		</view>
		<view class="bottom">
			<van-button round color="#FF6200" size="large" @click="onConfirm">确认</van-button>
		</view>
	</view>
</template>

<script>
import { getStoreList } from '@/api/api'
import baseUrl from '@/api/baseUrl';
export default {
	data() {
		return {
			baseUrl,
			zhdropdownOption: [{
				text: "综合排序",
				value: 1
			}, {
				text: "七天无理由",
				value: 2
			}, {
				text: "退货包运费",
				value: 3
			},
			{
				text: "极速退款",
				value: 4
			}
			],
			radio: -1,
			zhdropdownValue: 1,
			mddropdownOption: [],
			mddropdownValue: 0,
			list: [],
			arrs: [],
			id: '',
			longitude: '',
			latitude: ''
		};
	},
	onLoad(options) {
		this.id = options.id
		uni.getLocation({
			type: 'wgs84',
			success: (res) => {
				this.longitude = res.longitude
				this.latitude = res.latitude
				this.stateList()
			},
			fail: function (err) {
				console.log(err)
			}
		});

	},
	methods: {
		stateList() {
			getStoreList({ shop_id: this.id, longitude: this.longitude, latitude: this.latitude }).then(res => {
				if (res.code == 1) {
					this.list = res.data
					this.arrs = res.data
					let arr = [{
						text: "门店筛选",
						value: 0
					}]
					res.data.forEach(element => {
						arr.push({
							text: element.store_name,
							value: element.id
						})
					});
					this.mddropdownOption = arr
				}
			})
		},
		onMddropdownChange(e) {
			console.log(e)
			let index = e.detail
			if (index > 0) {
				let arr = []
				this.arrs.forEach(element => {
					if (element.id == index) {
						arr.push(element)
					}
				})
				this.list = arr
			} else {
				this.stateList()
			}
		},
		onConfirm() {
			let item = this.list[this.radio];
			uni.navigateTo({ url: '/long/productDetail/pick?item=' + JSON.stringify(item) })
		}
	},
}
</script>

<style lang="scss">
page {
	background-color: #f9f9f9;
}

.topbox {
	background-color: #fff;

	.searchbox {
		display: flex;
		align-items: center;
		padding-left: 30rpx;
		box-sizing: border-box;
		width: 100%;

		.adress {
			display: flex;
			align-items: center;
			justify-content: center;
			column-gap: 10rpx;
			font-size: 26rpx;

			.adimg {
				width: 22rpx;
				height: 26rpx !important;
				object-fit: cover;
			}
		}

		.search {
			flex: 1;
		}
	}

	.tabbox {
		padding: 0 40rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.van-dropdown-menu {
		background-color: transparent !important;
		box-shadow: none !important;
		color: #3D3D3D;
		font-size: 26rpx;
	}

	.van-dropdown-menu__title {
		padding: var(--dropdown-menu-title-padding, 0 24px 0 0);
	}

	.liaol {
		font-size: 26rpx;
		color: #3D3D3D;
	}
}

.content {
	margin-bottom: 60rpx;
	padding: 20rpx 36rpx;
	display: flex;
	flex-direction: column;
	row-gap: 20rpx;

	.item {
		border-radius: 16rpx;
		background: #FFFFFF;
		padding: 20rpx;
		box-shadow: 0px 0px 8rpx 0px rgba(0, 0, 0, 0.05);

		.chanpin {
			display: flex;
			column-gap: 20rpx;

			image {
				width: 176rpx;
				height: 176rpx;
			}

			.tright {
				display: flex;
				flex-direction: column;
				padding: 10rpx 0;
				row-gap: 10rpx;
				flex: 1;

				.title {
					color: #3D3D3D;
					display: flex;
					align-items: center;
					column-gap: 10rpx;
					font-size: 28rpx;
					color: #3D3D3D;
					width: 100%;

					.jltxt {
						border-radius: 4rpx;
						box-sizing: border-box;
						border: 0.8rpx solid #FF6200;
						font-size: 18rpx;
						color: #FF6200;
					}

					.juli {
						font-size: 24rpx;
						margin-left: auto;
					}
				}

				.distance {
					display: flex;
					column-gap: 10rpx;
					font-size: 22rpx;
					color: #3D3D3D;
					flex: 1;

					.orange {
						font-size: 24rpx;
						color: #FF6200;
					}
				}
			}

			.address {
				font-size: 24rpx;
				color: #3D3D3D;
			}
		}

		.ziti {
			display: flex;
			justify-content: space-between;
			align-items: center;
			border-radius: 8px;
			background: #FFEFDF;
			padding: 20rpx;
			font-size: 22rpx;
			color: #3D3D3D;
			margin: 20rpx 0;
		}
	}
}

.bottom {
	position: fixed;
	left: 0;
	bottom: 0;
	padding: 40rpx 30rpx;
	width: 100%;
	box-sizing: border-box;
	background-color: #fff;
}
</style>
